package com.trkj.dao.jpa;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.trkj.pojos.LmbConsumableCollar;
import com.trkj.pojos.LmbConsumableOutbound;
import com.trkj.pojos.LmbCousumablePurchasePlan;

public interface LmbConsumableCollarDAO extends CrudRepository<LmbConsumableCollar, String> {
	//分页显示领用单
	@Query("select s from LmbConsumableCollar s")
	public List<LmbConsumableCollar> findConsumableCollarByPage(Pageable pageable);

	@Query("select max(c.collarId) from LmbConsumableCollar c where c.collarId like ?1%")
    public String findMaxID(String a);
	
	@Query("select c from LmbConsumableCollar c where c.collarApprovepeople =?1 and c.collarState='待审批' order by c.collarId desc")
	public List<LmbConsumableCollar> findByApprovepeople(Pageable pageable,BigDecimal spr);
	
	@Query("select count(*) from LmbConsumableCollar c where c.collarApprovepeople =?1 and c.collarState='待审批'")
	public long countByApprovepeople(BigDecimal spr);
	
	@Query("select c from LmbConsumableCollar c where c.collarId =?1")
	public LmbConsumableCollar findByCollarId(String collarId);
	
	@Query("select c from LmbConsumableCollar c where c.collarApprovepeople =?1 and c.collarState='已审批' order by c.collarId desc")
	public List<LmbConsumableCollar> findYsp(Pageable pageable,BigDecimal spr);
	
	@Query("select count(*) from LmbConsumableCollar c where c.collarApprovepeople =?1 and c.collarState='已审批'")
	public long countfindYsp(BigDecimal spr);
	
	//分页查询所有已审批通过但未领用的领用单
	@Query("select c from LmbConsumableCollar c where c.collarState='已审批' and c.collarApproveresult='已通过' and c.collarCkstatus='未领用'")
	public List<LmbConsumableCollar> queryAllYspwly(Pageable pageable);
	
	@Query("select count(*) from LmbConsumableCollar c where c.collarState='已审批' and c.collarApproveresult='已通过' and c.collarCkstatus='未领用'")
	public long countAllYspwly();
	
}
